/*************************************************************************
	> File Name: send_chat.c
	> Author: Maureen 
	> Mail: 1437867946@qq.com 
	> Created Time: Mon 18 Jan 2021 07:53:42 PM CST
 ************************************************************************/

#include "head.h"

extern char name[20];
extern struct User *users;

//发送数据
void *send_chat(void *arg) {
    struct Msg msg;
    memset(&msg, 0, sizeof(msg));
    strcpy(msg.from, name);
    msg.type = CHAT_MSG;

    while (1) {
        memset(msg.msg, 0, sizeof(msg.msg));
        printf("Please input:\n");
        scanf("%s", msg.msg);
        for (int i = 0; i < MAXUSER; i++) {
            if (users[i].flag) {
                send(users[i].fd, &msg, sizeof(msg), 0);
            }
        }
    }
}
